<?php
class View_Bug_Manager_List extends CMF_Krypton_Core_View
{
	public function buildContent()
	{
		$dbc		= $this->registry->get( 'dbc' );
		$config		= $this->registry->get( 'config' );
		$request	= $this->registry->get( 'request' );
		$session	= $this->registry->get( 'session' );
		$auth		= $this->registry->get( 'auth' );
		$words		= $this->words['bug']['list'];

		$list	= new CMF_Krypton_View_Component_List( 'Collection_Bug' );
#		$list->setActionForm( 'listBugs' );
#		$list->setActions( $actions );
		$list->setCaption( $words['caption'] );
		$list->setColumnGroup( $words['colgroup'] );
		$list->setTemplates( 'bug.list', 'bug.listitem', 'paging' );
		$list->setLimitKey( 'bug_limit' );
		$list->setOffsetKey( 'bug_offset' );
#		$list->setHeads( $heads );
		$list->setPagingOptions( $options );
		$list->setTransformer( $this, 'transformListEntry' );

		$list->collectBugs();
		if( $session->get( 'bug_order' ) )
			$list->orderBy( $session->get( 'bug_order' ), $session->get( 'bug_direction' ) );
		if( $session->get( 'administration_users_username' ) )
			$list->withUsernameLike( $session->get( 'administration_users_username' ) );
		if( $session->get( 'administration_users_email' ) )
			$list->withEmailLike( $session->get( 'administration_users_email' ) );

		if( "" !== (string) $session->get( 'bug_bug_id' ) )
			$list->withId( $session->get( 'bug_bug_id' ) );
		if( "" !== (string) $session->get( 'bug_server' ) )
			$list->withServers( array( $session->get( 'bug_server' ) ) );
		if( "" !== (string) $session->get( 'bug_project' ) )
			$list->withProject( array( $session->get( 'bug_project' ) ) );
		if( "" !== (string) $session->get( 'bug_type' ) )
			$list->withTypes( array( $session->get( 'bug_type' ) ) );
		if( "" !== (string) $session->get( 'bug_priority' ) )
			$list->withPriorities( array( $session->get( 'bug_priority' ) ) );
		if( "" !== (string) $session->get( 'bug_title' ) )
			$list->withTitleLike( $session->get( 'bug_title' ) );
		if( is_array( $session->get( 'bug_status' ) ) && count( $session->get( 'bug_status') ) )
		{
			$states	= array();
			foreach( $session->get( 'bug_status') as $status )
				if( strlen( trim( $status ) ) )
					$states[]	= $status;
			if( count( $states ) )
				$list->withStates( $states );
		}
		if( "" !== (string) $session->get( 'bug_reporter' ) )
			$list->withAuthor( $session->get( 'bug_reporter' ) );
		if( "" !== (string) $session->get( 'bug_developer' ) )
			$list->withDeveloper( $session->get( 'bug_developer' ) );
		$list	= $list->getList();

		$info_count	= " ( ".$count_list." / ".$count_all." )";
		$info_offset	= " [ ".($session->get( 'bug_offset' ) + ($count_list?1:0))." - ".($session->get( 'bug_offset' )+$count_list)." ]";
		$caption_info	= $info_count.$info_offset;
		$ui['caption']		= $this->html->TableCaption( $words['caption'].$caption_info );
		$ui['heading']		= $words['heading'];
		return $this->loadTemplate( 'bug.list', $ui );
	}

	public function transformListEntry( $item )
	{
		$request	= $this->registry->get( 'request' );
		$item['style']			= ++$i % 2 ? 'list1' : 'list2';
		$item['icon_url']		= "";#$this->getIconURL( $bug['priority'], $bug['status'] );
		$item['title']			= $bug['title'];#$this->str_shorten( $bug['title'], $config['layout']['shorten_content'] );
		$item['link']			= $this->html->Link( "?link=".$request->get( 'link' )."&bug_id=".$bug['bug_id'], $title );
		$item['description']	= $bug['description'];#nl2br( $this->includeBugLink( $bug['description'] ) );
		return $item;
	}
}
?>
